import {connect} from 'react-redux'
import React, {Component} from 'react'
import { Link } from "react-router-dom";
import Header from "../components/header";

import {getRecordsInfo} from "../redux/actions/userAction"
export class TodayInput extends Component {
  constructor (props){
   super(props)
   this.state= {
   }
}

componentWillMount(){
  const {dispatch} =this.props
  dispatch(getRecordsInfo())
}
   render() {
    const {user} = this.props
    let record = user.get("todayrecords")
    let todayrecords=[
      {
        title:"投注金额",
        money:record.usertOrder
      },{
        title:"中奖金额",
        money:record.usertWin
      },{
        title:"返点金额",
        money:record.usertBackPoint
      },{
        title:"活动礼金",
        money:record.usertBackFree
      },{
        title:"充值金额",
        money:record.usertPostMoney
      },{
        title:"提现金额",
        money:record.usertWithdrawMoney
      }
    ]
   return <div className="todayinputcontext">
     <Header title="今日盈亏" {...this.props}></Header>
      <div className="todayinput">
        <div className="inputmoney">
            <h3>盈利金额</h3>
            <p>{record.usertWinLost}</p>
        </div>
        <h4>盈亏计算公式：中奖-投注+活动+返点</h4>
        <div className="inputitem">
          <ul>
            {todayrecords.map((item,index)=>{
              return  <li key={index}>
                <h3>{item.title}</h3>
                <p>{index == 2 ? new Number(item.money).toFixed(3) : item.money}</p>
              </li>
            })}
          </ul>
        
        </div>
      </div>

   </div>
   }
}


function mapStateToProps(state) {
  return {
    user: state.user // gives our component access to state through props.My
  }
}

export default connect(mapStateToProps)(TodayInput)